<?php
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>外卖网-订单管理</title>
<link href="style/css.css" rel="stylesheet" type="text/css">

<script src="js/jquery-1.9.0.min.js" type="text/javascript"></script>
<script src="js/My97DatePicker/WdatePicker.js"
      type="text/javascript"></script> 
<script src="js/jquery.blockUI.js" type="text/javascript"></script>
<script type="text/javascript"> 
$(document).ready(function(){
$("#huifuContent").val($("#huifuContent").val().replace(/[ ]/g,""));



});

function xiadan(shoporderid){
var xiaod= $("#dingdanhaoref"+shoporderid).html();
xiaod = xiaod.replace(/<[^>].*?>/g,"");  
	var dingdanhaoma=xiaod;
	dingdanhaoma=dingdanhaoma.replace(/[ ]/g,"");

var xiaoding = $("#dingdanxiangxi"+shoporderid).html();  
xiaoding = xiaoding.replace(/<[^>].*?>/g,"");  
	var dingdanxiangxi=xiaoding;
	dingdanxiangxi=dingdanxiangxi.replace(/[ ]/g,"");
	var xiaodi = $("#dingdandizhi"+shoporderid).html();
xiaodi = xiaodi.replace(/<[^>].*?>/g,"");  
	var dingdandizhi=xiaodi;
	dingdandizhi=dingdandizhi.replace(/[ ]/g,"");
$.ajax({ 
    type:'post', //传送的方式,get/post 
    url:'shopxiacheAjax.php', //发送数据的地址 
    cache:'false', 
    data:'shoporderid='+shoporderid+"&which=0", 
    dataType: 'text',
    success:function(data) 
    { if(data=="yes"){

 if($("#faisownphone").val()==1){
    	if($("#thisownphone").val().length>0){
    	$.ajax({ 
               type:'post', //传送的方式,get/post 
               url:'post_mt1.php', //发送数据的地址 
               cache:'false', 
               data:'name='+$("#thisownphone").val()+"&sendValue="+"订单:"+dingdanhaoma+",订单内容:"+dingdanxiangxi+",订餐人:"+$("#usernameref"+shoporderid).html()+",送餐地址:"+dingdandizhi+",送餐电话:"+$("#mobileref"+shoporderid).html(),  
              success:function(data) 
                { 
      
                }
            });
		}

		$.ajax({ 
               type:'post', //传送的方式,get/post 
               url:'post_mt1.php', //发送数据的地址 
               cache:'false', 
               data:'name='+$("#mobileref"+shoporderid).html()+"&sendValue="+"您的订单已确认,订单:"+dingdanhaoma+".订单内容:"+dingdanxiangxi,  
              success:function(data) 
                { 
      
                }
            });
}
      alert("下单成功");
      $("#orderstatus"+shoporderid).html("订单完成");
      $("#caozuo"+shoporderid).html("");
    }



    }
  }) 




}

function chedan(shoporderid){
$.ajax({ 
    type:'post', //传送的方式,get/post 
    url:'shopxiacheAjax.php', //发送数据的地址 
    cache:'false', 
    data:'shoporderid='+shoporderid+"&which=1", 
    dataType: 'text',
    success:function(data) 
    { if(data=="yes"){
      alert("撤单成功");
      $("#orderstatus"+shoporderid).html("订单退订");
       $("#caozuo"+shoporderid).html("<a href='javascript:xiadan("+shoporderid+")'>下单</a>");
    }
    }
  }) 



}
var huifuid="";

function submitHuifu(){
var huifuContent=$("#huifuContent").val();
$.ajax({ 
    type:'post', //传送的方式,get/post 
    url:'huifuAjax.php', //发送数据的地址 
    cache:'false', 
    data:'huifuContent='+huifuContent+"&huifuid="+huifuid, 
    dataType: 'text',
    success:function(data) 
    { 
      window.location.reload();
    }
  }) 


}

function huifu(did){
  huifuid=did;

   //给box_btn绑定一个鼠标点击的事件
$.blockUI({    //当点击事件发生时调用弹出层
  message: $('#loginbox5'),    //要弹出的元素box
  css: {    //弹出元素的CSS属性
    border:'5px solid #334343',
    textAlign: 'left',
  width: '490px',
  top:  ($(window).height() - 290) /2 + 'px', 
    left: ($(window).width() - 490) /2 + 'px', 
  cursor: 'auto'
       },
  overlayCSS: {
  opacity: '0.7' 
            }
         });
$('.blockOverlay').attr('title','单击关闭').click($.unblockUI);   //遮罩层属性的设置以及当鼠标单击遮罩层可以关闭弹出层
$('.close').click($.unblockUI);  //也可以自定义一个关闭按钮来关闭弹出层


}
$(document).ready(function(){


  var riqinian=$("#riqiNian").val();
  var riqiyue=$("#riqiYue").val();
$.ajax({ 
    type:'post', //传送的方式,get/post 
    url:'getAllShopMarketing.php', //发送数据的地址 
    cache:'false', 
    data:'riqinian='+riqinian+"&riqiyue="+riqiyue, 
    dataType: 'text',
    success:function(data) 
    { 
      var hi=data.split(",");
      $("#fenshu").html(hi[1]);
      $("#jiage").html(hi[0]);
    }
  }) 





});

function getAllOrderMoney(sid){


  var riqinian=$("#riqiNian").val();
  var riqiyue=$("#riqiYue").val();
$.ajax({ 
    type:'post', //传送的方式,get/post 
    url:'getAllShopMarketing.php', //发送数据的地址 
    cache:'false', 
    data:'riqinian='+riqinian+"&riqiyue="+riqiyue+"&sid="+sid, 
    dataType: 'text',
    success:function(data) 
    { 
      var hi=data.split(",");
      $("#fenshu").html(hi[1]);
      $("#jiage").html(hi[0]);
    }
  }) 



}
$(function(){ 
//Default Action 
$(".tab_content").hide(); //Hide all content 
$("ul.tabs li:first").addClass("active").show(); //Activate first tab 
$(".tab_content:first").show(); //Show first tab content 
//On Click Event 
$("ul.tabs li").click(function() { 
$("ul.tabs li").removeClass("active"); //Remove any "active" class 
$(this).addClass("active"); //Add "active" class to selected tab 
$(".tab_content").hide(); //Hide all tab content 
var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content 
$(activeTab).fadeIn(); //Fade in the active content 
return false; 
}); 
}); 
</script> 
<script type="text/javascript"> 
$(function(){
$('#login').click(function(){   //给box_btn绑定一个鼠标点击的事件
$.blockUI({    //当点击事件发生时调用弹出层
  message: $('#loginbox'),    //要弹出的元素box
  css: {    //弹出元素的CSS属性
    border:'5px solid #334343',
    textAlign: 'left',
	width: '490px',
	top:  ($(window).height() - 290) /2 + 'px', 
    left: ($(window).width() - 490) /2 + 'px', 
	cursor: 'auto'
       },
  overlayCSS: {
	opacity: '0.7' 
	          }
         });
$('.blockOverlay').attr('title','单击关闭').click($.unblockUI);   //遮罩层属性的设置以及当鼠标单击遮罩层可以关闭弹出层
$('.close').click($.unblockUI);  //也可以自定义一个关闭按钮来关闭弹出层

});

$('#shoplogin').click(function(){   //给box_btn绑定一个鼠标点击的事件
  $.blockUI({    //当点击事件发生时调用弹出层
    message: $('#loginbox'),    //要弹出的元素box
    css: {    //弹出元素的CSS属性
      border:'5px solid #334343',
      textAlign: 'left',
    width: '490px',
    top:  ($(window).height() - 290) /2 + 'px', 
      left: ($(window).width() - 490) /2 + 'px', 
    cursor: 'auto'
         },
    overlayCSS: {
    opacity: '0.7' 
              }
   });
  $('.blockOverlay').attr('title','单击关闭').click($.unblockUI);   //遮罩层属性的设置以及当鼠标单击遮罩层可以关闭弹出层
  $('.close').click($.unblockUI);  //也可以自定义一个关闭按钮来关闭弹出层
  $("#alllogin").attr("action","login-shop.php");
  });

});
</script> 

<?php
include('system/db/conn.php');
$meiye=5;
$local_arraya = mysql_query("select count(*) from do_deal_order where supplier_id=".$_SESSION['supplierid']);

$rowa = mysql_fetch_row($local_arraya);
$zongtiaoshu=$rowa[0];
mysql_free_result($local_arraya);

$local_arrayb = mysql_query("select tel,sms_send_flag from do_supplier_location where supplier_id=".$_SESSION['supplierid']);

$rowb = mysql_fetch_row($local_arrayb);
$shangpuphpone=$rowb[0];
$faisownphone=$rowb[1];
mysql_free_result($local_arrayb);




$yeshu=floor($zongtiaoshu/$meiye);
if(!($zongtiaoshu%$meiye==0)){
	$yeshu+=1;
}


?>
</head>

<body>
<input type="hidden" id="thisownphone" value="<?php echo $shangpuphpone ?>"/> 
<input type="hidden" id="faisownphone" value="<?php echo $faisownphone ?>"/> 
<div id="loginbox" style="display:none">
  <div class="login_title">会员登录</div>
  <div class="login_input">
    <div class="input"><span>账号：</span><span><input name="user" type="text" /></span></div>
    <div class="input"><span>密码：</span><span><input name="pwd" type="password" /></span></div>
    <div class="login_input_1 clearfix"><input name="" type="checkbox" value="" id="store1" /><label for="store1">自动登录</label><a href="#">找回密码</a></div>
    <div class="reg clearfix"><span><input class="login_btn" name="" type="image" src="images/login.jpg" /></span><span>还没有账号？</span><a href="#">立即注册</a></div>
  </div>
</div>





<div id="loginbox5" style="display:none">
  <div class="login_title">回复评论</div>
  <div class="login_input">
    <div class=""><span>内容：</span><span>
    
    <textarea cols="40" rows="10" name="username" id="huifuContent"></textarea>
    </span></div>
   
    <div class="reg clearfix"><span><input class="login_btn" onclick="submitHuifu()" name="submit" type="image" src="images/save.jpg" /></span></div>
  </div>

</div>

<div class="top">
  <div class="top_content clearfix"><span class="left"><a href="index.php"><img src="images/wmwlogo.png"></a></span><span class="right">
 
  <?php
    if(isset($_SESSION['username'])){
      if($_SESSION['logintype']=="userlog"){
     echo '<a href="member.php">'.$_SESSION['username'],'欢迎你！</a>';
}elseif ($_SESSION['logintype']=="supplierlog") {
   echo '<a href="shop-xx.php">'.$_SESSION['username'],'欢迎你！</a>';
}
      echo '<a href="login.php?action=logout">登出</a>';
    }else{
      echo ' <a href="#" id="login">';
      echo '登录';
      echo '</a> / <a href="reg11.php">注册</a>';
    }
  ?>
  <?php  
      if(!isset($_SESSION['username'])  ){
   ?>
  | <a href="#"  id="shoplogin">店铺登录</a></span></div>
  <?php 
    }

   ?>
</div>

<div class="content1 clearfix">
  <div class="content_con clearfix">
    <div class="box_left left">
      <div class="box">
        <div class="box_title"><div class="box_title_con1 left"><?php echo $_SESSION['username'] ?></div></div>
        <ul class="clearfix box_ul">
          <li><span class="ico5"><a href="shop-xx.php">店铺信息</a></span></li>
          <li class="liselect"><span class="ico6select"><a href="shop-dd.php">订单管理</a></span></li>
          <li><span class="ico7"><a href="shop-cd.php">菜单管理</a></span></li>
          <li><span class="ico4"><a href="shop-pass.php">修改密码</a></span></li>
        </ul>
      </div>
      <div class="box">
        <div class="box_title"><div class="box_title"><div class="box_title_title">销售统计</div></div></div>
        <ul class="clearfix box_ul_1">
          <li> 
            <span>日期</span>
            <span>
              <input type="text" name="open_time2" id="riqiNian" onchange="getAllOrderMoney(<?php echo $_SESSION['supplierid'] ?>)" value="<?php echo date("Y") ?>"  style="width:78px;height:23px;" size="20" onfocus="WdatePicker({skin:'whyGreen',dateFmt:'yyyy'})">年
              
            </span>
            <span>
              <input type="text" name="open_time2"  id="riqiYue" onchange="getAllOrderMoney(<?php echo $_SESSION['supplierid'] ?>)" value="<?php echo date("m") ?>" style="width:22px;height:23px;" size="20" onfocus="WdatePicker({skin:'whyGreen',dateFmt:'MM'})">月
              
            </span>
          </li>
          <li><span class="count_tit">单量</span><span id="fenshu">0</span>份</li>
          <li><span class="count_tit">销售额</span><span id="jiage">0</span>元</li>
          
        </ul>
      </div>
    </div>
    <div class="box_right1 right">
      <div class="box" style="margin-bottom:0px;">
        <div class="box_title"><div class="box_title_title">菜单管理</div></div>
        <div class="box_menu">
          <table width="100%" border="0" cellpadding="0" cellspacing="0" class="orderlist">
            <tr>
              <th width="80">订单号</th>
              <th width="70">下单时间</th>
              <th width="60">会员</th>
              <th width="80">电话</th>
              <th width="130">餐点</th>
              <th width="160">地址</th>
              <th width="50">价钱</th>
              <th >订单状态</th>
              <th>操作</th>
            </tr>

            <?php
            date_default_timezone_set("Asia/Shanghai");
          $i = 1 ;
          $fenyesql="";
          if(isset($_GET['refyeshu'])){
          	$zhiqiantiao=($_GET['refyeshu']-1)*$meiye;
          	$fenyesql="select * from do_deal_order where supplier_id=".$_SESSION['supplierid']." order by create_time desc limit ".$zhiqiantiao.",".$meiye." ";
          }else{

          		$fenyesql="select * from do_deal_order where supplier_id=".$_SESSION['supplierid']."  order by create_time desc limit 5";
          }

         
          $area_query = mysql_query($fenyesql);
          while($row = mysql_fetch_array($area_query)){
            echo "<tr><td align='center' class='table_left' id='dingdanhaoref".$row['id']."'>";
            echo  substr($row['order_sn'],0,8);
            echo "<br>";
            echo  substr($row['order_sn'],8);
            echo "</td>";
            echo "<td  align='center'>";
            echo date("Y-m-j H:i:s",$row['create_time']);
            echo "</td>";
            echo "<td align='center' id='usernameref".$row['id']."'>";
            echo $row['user_name'];
            echo "</td>";
            echo "<td align='center' id='mobileref".$row['id']."' >";
            echo $row['mobile'];
            echo "</td>";

?>
            <td align='center' class='table_dinner' id='dingdanxiangxi<?php echo $row['id'] ?>'>
            <?php 

	$arrayzhengti = split(" ",$row['food']);
			$count_array = count($arrayzhengti);
					$shuliang=0;
$x=0;
				for($x==0;$x<$count_array;$x++){



				$arrayFensan=split(",",$arrayzhengti[$x]);	

				$shuliang+=$arrayFensan[1];
			$local_array2 = mysql_query("select * from do_supplier_location_menu 	 where id=".$arrayFensan[0]);
			$row3 = mysql_fetch_row($local_array2);
				
			mysql_free_result($local_array2); 
            echo $row3[2]."*".$arrayFensan[1];
            if($x==$count_array){

            }else{
            	echo "<br/>";
            }

}

?>
            </td>
<?php

            echo "<td align='center' id='dingdandizhi".$row['id']."'>";
            echo $row['address'];
            echo "</td>";
            echo "<td align='center'>";
            echo $row['total_price'];
            echo "</td>";
            echo "<td align='center' id='orderstatus".$row['id']."'>";
            if($row['order_status']==1){
              echo "订单处理中";

            }elseif ($row['order_status']==2) {
              echo "订单退订";
            }elseif ($row['order_status']==3) {
              echo "订单完成";
            }
            
            

            echo "</td>";
            echo "<td align='center' class='table_right' id='caozuo".$row['id']."'>";
            if($row['order_status']==1){
              echo "<a href='javascript:xiadan(".$row['id'].")'>下单</a>&nbsp;&nbsp;<a href='javascript:chedan(".$row['id'].")'>撤单</a>";
            }elseif ($row['order_status']==2) {
              echo "<a href='javascript:xiadan(".$row['id'].")'>下单</a>";
            }elseif ($row['order_status']==3) {
              echo "";
            }
           

            echo "</td>";
          }
          mysql_free_result($area_query);
        ?>

            

            
          </table>
        </div>
         <div class="pagelist clearfix">
          <div class="prew left">
          <?php
          if($yeshu>0){
          ?>
          <a href="shop-dd.php?refyeshu=1"><img src="images/page_left.jpg"></a>
        <?php
        }?>
          </div>
          <ul class="left">
          <?php
          $refyecheck=false;
          if(isset($_GET['refyeshu'])){
          	$refyecheck=true;
          }
          	for ($i=1; $i <=$yeshu ; $i++) { 
          		# code...
          		if(!$refyecheck){
          			if($i==1){
          				echo '<li class="pageselect">'.$i.'</li>';
          			}else{
						echo '<li ><a href="shop-dd.php?refyeshu='.$i.'">'.$i.'</a></li>';

          			}
          		}else{
          			if($i==$_GET['refyeshu']){
          					echo '<li class="pageselect">'.$i.'</li>';

          			}else{
          				echo '<li ><a href="shop-dd.php?refyeshu='.$i.'">'.$i.'</a></li>';
          			}


          		}
        	
            
          

			}
           ?> 
            <!-- <li class="pageselect">2</li>
            <li><a href="#">3</a></li> -->
          </ul>
          <div class="next left">
          <?php
          if($yeshu>0){
          ?>
          <a href="shop-dd.php?refyeshu=<?php echo $yeshu ?>"><img src="images/page_right.jpg"></a>
<?php
         }
          ?>
          </div>
        </div>
      </div>
      <div class="box" style="border-top:0px;margin-top:-1px;">
        <div class="box_title"><div class="box_title_title">评论</div></div>
        <div class="box_content clearfix" style="padding-top:10px;">
          <ul class="message">

<?php
  
    
      $sql_message="SELECT m.content,m.create_time,u.user_name,m.admin_reply,u.level_id,m.id FROM do_message m,do_user u  where m.user_id = u.id and m.supplier_id=".$_SESSION['supplierid']." order by m.create_time desc limit 6";
  $result = mysql_query($sql_message);
  while($row = mysql_fetch_array($result))
       {
?>



            <li class="clearfix"><span class="left">·<?php echo $row['content'] ?></span><span class="right"><a href="javascript:huifu(<?php echo $row['id'] ?>)">回复</a></span><span class="right"><?php echo date("Y-m-j",$row['create_time']) ?></span><span class="right"><?php echo $row['user_name'] ?><img src="images/lv<?php echo $row['level_id'] ?>.jpg"></span></li>

<?php
	if(!(is_null($row['admin_reply']))||!($row['admin_reply']=="")){
	
?>
              <li class="clearfix"><span class="left">·管理员回复:<?php echo $row['admin_reply'] ?></span><span class="right"></span><span class="right"></span><span class="right"></span></li>
       <?php
}

       ?>     
          

<?php

}
?>
          </ul>
          <div class="right"><!-- <input type="image" src="images/history.jpg"> --></div>
        </div>
      </div>
    </div>
  </div>
</div>

<?php include('bottom.php') ?>
</body>
</html>
